﻿#include "btform.h"
#include "ui_btform.h"


BtForm::BtForm(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::BtForm)
{
    ui->setupUi(this);

    // 设置BtFrom上lineBox部分的4个Label的动画效果
    initPropertyAnimation();

    //隐藏动画效果
    ui->lineBox->hide();
}

BtForm::~BtForm()
{
    delete ui;
}

void BtForm::setIconAndText(const QString &btIcon, const QString &btText, int pageId)
{
    //设置按钮的图标
    ui->btIcon->setPixmap(QPixmap(btIcon));

    //设置按钮的文字
    ui->btText->setText(QString(btText));

    //将按钮和QQNMusic中的page页面进行关联
    this->_pageId = pageId;
}

int BtForm::getPageId() const
{
    return this->_pageId;
}

void BtForm::clearbackGroundColor()
{
    ui->btStyle->setStyleSheet("#btStyle:hover{background-color:#D8D8D8;}");
}

void BtForm::initPropertyAnimation()
{
/*
 *BtFrom上的动画效果
    设置动画效果步骤：
    1. 创建QPropertyAnimation 对象
    2. 设置动画的持续时间
    3. 设置动画的关键帧
    4. 设置动画的循环次数【⾮必须】，如果未调⽤动画默认执⾏⼀次
    5. 开启动画
    6. 动画运⾏结束时，会发射finished信号，如果需要进⾏额外处理时，处理该信号即可
*/
    // 设置line1的动画效果
    line1 = new QPropertyAnimation(ui->line1, "geometry", this);
    line1->setDuration(1500);//单位:ms
    line1->setKeyValueAt(0, QRect(0, 15, 3, 0));
    line1->setKeyValueAt(0.5, QRect(0, 0, 3, 15));
    line1->setKeyValueAt(1, QRect(0, 15, 3, 0));
    line1->setLoopCount(-1);
    line1->start();

    // 设置line2的动画效果
    line2 = new QPropertyAnimation(ui->line2, "geometry", this);
    line2->setDuration(1600);//单位:ms
    line2->setKeyValueAt(0, QRect(8, 15, 3, 0));
    line2->setKeyValueAt(0.5, QRect(8, 0, 3, 15));
    line2->setKeyValueAt(1, QRect(8, 15, 3, 0));
    line2->setLoopCount(-1);
    line2->start();

    // 设置line3的动画效果
    line3 = new QPropertyAnimation(ui->line3, "geometry", this);
    line3->setDuration(1700);//单位:ms
    line3->setKeyValueAt(0, QRect(16, 15, 3, 0));
    line3->setKeyValueAt(0.5, QRect(16, 0, 3, 15));
    line3->setKeyValueAt(1, QRect(16, 15, 3, 0));
    line3->setLoopCount(-1);
    line3->start();

    // 设置line4的动画效果
    line4 = new QPropertyAnimation(ui->line4, "geometry", this);
    line4->setDuration(1500);//单位:ms
    line4->setKeyValueAt(0, QRect(24, 15, 3, 0));
    line4->setKeyValueAt(0.5, QRect(24, 0, 3, 15));
    line4->setKeyValueAt(1, QRect(24, 15, 3, 0));
    line4->setLoopCount(-1);
    line4->start();
}

void BtForm::showAnimation(bool isShow)
{
    if(isShow)
    {
        ui->lineBox->show();
    }
    else
    {
        ui->lineBox->hide();
    }
}

void BtForm::mousePressEvent(QMouseEvent *event)
{
    (void)event;
    //1.当按下按钮后,需要修改其背景颜色
    ui->btStyle->setStyleSheet("#btStyle{background-color: rgb(30, 206, 154);}");

    //2.当按下按钮后,需要切换bodtRight区域的Page页面

    emit btClick(_pageId);
}





